package com.berchen.数据结构.哈希表;

/**
 * 哈希表
 */
public class HashTab {

    private EmpLinkedList [] empLinkedLists;
    private int size;


    public HashTab() {
        new HashTab(10);
    }

    public HashTab(int size) {
        this.size=size;
        this.empLinkedLists=new EmpLinkedList[this.size];
        for(int i =0;i<this.size;i++){
            this.empLinkedLists[i]=new EmpLinkedList();
        }
    }
    public Emp select(int id){
        return this.empLinkedLists[getIndex(id)].select(id);
    }
    public void add(Emp emp){
        this.empLinkedLists[getIndex(emp.getId())].add(emp);
    }
    public void list(){
        for (int i =0;i<size;i++){
            this.empLinkedLists[i].list(i);
        }
    }

    /**
     * 获取该数据应该保存在哪个链表中
     * @param id
     * @return
     */
    public int getIndex(int id ){
        return id%this.size;
    }
}
